package us.nchu.tomtiger.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import us.nchu.tomtiger.dao.UserDao;
import us.nchu.tomtiger.dao.UserPendingDao;
import us.nchu.tomtiger.model.UserPending;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by XiongXuan on 2018/1/11.
 */
@Service
public class UserPendingService {
    @Resource
    private UserPendingDao userPendingDao;
    @Resource
    private UserDao userDao;

    public List<UserPending> getUncheckedList() {
        return userPendingDao.queryForUnchecked();
    }

    public void createUserPending(UserPending userPending) {
        userPendingDao.insert(userPending);
    }

    @Transactional
    public void updateUserType(UserPending userPending, String adminId) {
        userPendingDao.checkAndUpdateUser(userPending, adminId);
        userDao.updateUserType(userPending.getPhoneNumber(), userPending.getChangedUserType());
    }
}
